var cancelButton  ;
function nextView(){
	 if(cancelButton == false){ 
		 pickerSelectedValue = picker.getValue(); 
		 
		 ///info for scheduele :
		 // time - pickerSelectedValue
		 // busses - selectedBusses[]
		 //station -stationId
		 var bussesTime  = Ext.StoreMgr.lookup('BussesTime');
			
		 var currentHour = pickerSelectedValue.time_hour+":"+pickerSelectedValue.time_minute;
		  var bussesList ;
		  bussesList =  selectedBusses[0];
		 for (var i=1 ; i < selectedBusses.length; i++) {
			 bussesList = bussesList + ","+ selectedBusses[i];
			 
		  }
		  
		  bussesTime.getProxy().url = 'app/data/getHours.php?hour='+currentHour+'&id_bus='+bussesList+'&id_station='+stationId+'&id_day='+pickerSelectedValue.time_day ;
		  bussesTime.load();
		   
		  
	 }
	 else {
		  var nextBtn = obj.application.viewport.query('#nextBtn')[0];
		  nextBtn.hide();
	 }
}
 

function createPicker(){
cancelButton = false;
//////////////////////PICKER///////////////////////
picker = new   Ext.Picker( {
useTitles: true,
fullscreen: true,
cancelButton: {
	iconCls: 'arrow_left', 
	   iconMask: true,
	   centered: true,  
	   ui: 'plain',
},    
doneButton: {
		iconCls: 'arrow_right', 
	   iconMask: true,
	   centered: true,  
	   ui: 'plain',
       // handler: nextView
},  
slots: [ 
     {
         name : 'time_day',
         title: 'Day',
         data : [
             {text: 'Monday-Friday', value:  1 },
//             {text: 'Tuesday', value: '2'}, 
//             {text: 'Wendsday', value: '3'},  
//             {text: 'Thursday', value: '4'}, 
//             {text: 'Friday', value: '5'}, 
             {text: 'Saturday', value:  2 }, 
             {text: 'Sunday', value:  3 },  		             
         ]
     },	         
     {
         name : 'time_hour',
         title: 'Hour',
         data : [
             {text: '0', value: 0},
             {text: '1', value: 1}, 
             {text: '2', value: 2}, 
             {text: '3', value: 3}, 
             {text: '4', value: 4}, 
             {text: '5', value: 5}, 
             {text: '6', value: 6}, 
             {text: '7', value: 7}, 
             {text: '8', value: 8}, 
             {text: '9', value: 9}, 
             {text: '10', value: 10}, 
             {text: '11', value: 11}, 
             {text: '12', value: 12}, 
             {text: '13', value: 13}, 
             {text: '14', value: 14}, 
             {text: '15', value: 15}, 
             {text: '16', value: 16}, 
             {text: '17', value: 17}, 
             {text: '18', value: 18}, 
             {text: '19', value: 19}, 
             {text: '20', value: 20}, 
             {text: '21', value: 21}, 
             {text: '22', value: 22},  
             {text: '23', value: 23},  
             
         ]
     },
     {
         name : 'time_minute',
         title: 'Minute',
         data : [
             {text: '00', value: 0},
             {text: '01', value: 1},
             {text: '02', value: 2},
             {text: '03', value: 3},
             {text: '04', value: 4},
             {text: '05', value: 5},
             {text: '06', value: 6},
             {text: '07', value: 7},
             {text: '08', value: 8},
             {text: '09', value: 9},
             {text: '10', value: 10},
             {text: '11', value: 11},
             {text: '12', value: 12},
             {text: '13', value: 13},
             {text: '14', value: 14},
             {text: '15', value: 15},
             {text: '16', value: 16},
             {text: '17', value: 17},
             {text: '18', value: 10},
             {text: '19', value: 19},
             {text: '20', value: 20},
             {text: '21', value: 21},
             {text: '22', value: 22},
             {text: '23', value: 23},
             {text: '24', value: 24},
             {text: '25', value: 25},
             {text: '26', value: 26},
             {text: '27', value: 27},
             {text: '28', value: 28},
             {text: '29', value: 29},
             {text: '30', value: 30},
             {text: '31', value: 31},
             {text: '32', value: 32},
             {text: '33', value: 33},
             {text: '34', value: 34},
             {text: '35', value: 35},
             {text: '36', value: 36},
             {text: '37', value: 37},
             {text: '38', value: 38},
             {text: '39', value: 39},
             {text: '40', value: 40},
             {text: '41', value: 41},
             {text: '42', value: 42},
             {text: '43', value: 43},
             {text: '44', value: 44},
             {text: '45', value: 45},
             {text: '46', value: 46},
             {text: '47', value: 47},
             {text: '48', value: 48},
             {text: '49', value: 49},
             {text: '51', value: 51},
             {text: '51', value: 51},
             {text: '51', value: 51},
             {text: '53', value: 53},
             {text: '54', value: 54},
             {text: '55', value: 55},
             {text: '56', value: 56},
             {text: '57', value: 57},
             {text: '58', value: 58},
             {text: '59', value: 59}, 
         ]
     }
 ], 
  listeners: {
	  "pick":function(picker){

		  picker.dockedItems.items[0].setTitle("When...");
	  },
	  "cancel":function(picker){
		  cancelButton = true; 
	  },
      "hide": function(picker) { 
    	  
    	   nextView();
     
      },
      "show": function(picker){
    	  
    	  var now = new Date();
    	  var td = 1,th=12,tm=12;
    	  var today;
    	  today = now.getDay();
    	 if(today == 0) td= 3;
    	   else if(today <6) td= 1;
    	   		else  if(today == 6) td= 2;
    	  		
    	  th= now.getHours();
    	  tm = now.getMinutes() ;
    	  
    	  picker.setValue({time_day: td}, true);
    	  picker.setValue({time_hour: th}, true);
    	  picker.setValue({time_minute: tm}, true);
      }
  }		

}); 
 picker.dockedItems.items[0].dock="bottom";
picker.dockedItems.items[0].setTitle("When...(now?)");
}
Ext.regController('Time',{
	
	// provides a choice for the time to choose
	show: function(){
		
		obj= this;
		//sets title
		setTitle(this,"When?"); 
		
		
		
		createPicker();
		
		
		//get current time 
		currentDate = new Date();
		picker.show();
		 
		//BUTTONS
        
},
});